import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CategoryVO, CategoryForm, CategoryQuery } from '@/api/goods/category/types';

/**
 * 查询品牌列表
 * @param query
 * @returns {*}
 */

export const listCategory = (query?: CategoryQuery): AxiosPromise<CategoryVO[]> => {
  return request({
    url: '/order/goodsCategory/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询品牌详细
 * @param id
 */
export const getCategory = (id: string | number): AxiosPromise<CategoryVO> => {
  return request({
    url: '/order/goodsCategory/' + id,
    method: 'get'
  });
};

/**
 * 查询品牌详细
 */
export const getCategoryAllList = (): AxiosPromise<CategoryVO> => {
  return request({
    url: '/order/goodsCategory/allList',
    method: 'get'
  });
};

/**
 * 新增品牌
 * @param data
 */
export const addCategory = (data: CategoryForm) => {
  return request({
    url: '/order/goodsCategory',
    method: 'post',
    data: data
  });
};

/**
 * 修改品牌
 * @param data
 */
export const updateCategory = (data: CategoryForm) => {
  return request({
    url: '/order/goodsCategory',
    method: 'put',
    data: data
  });
};

/**
 * 删除品牌
 * @param id
 */
export const delCategory = (id: string | number | Array<string | number>) => {
  return request({
    url: '/order/goodsCategory/' + id,
    method: 'delete'
  });
};

/**
 * 状态修改
 * @param goodsCategoryId 客户端id
 * @param status 状态
 */
export function changeStatus(goodsCategoryId: string, status: string) {
  const data = {
    goodsCategoryId,
    status
  };
  return request({
    url: '/order/goodsCategory/changeStatus',
    method: 'put',
    data: data
  });
}

export default {
  list:listCategory,
  get:getCategory,
  add:addCategory,
  update:updateCategory,
  del:delCategory,
  getCategoryAllList:getCategoryAllList
}